package com.un.ebs.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.un.ebs.sys.domain.AppRule;
import com.un.ebs.sys.dto.AppRuleAddDto;
import com.un.ebs.sys.dto.AppRuleUpdateDto;
import com.un.ebs.sys.mapper.AppRuleMapper;
import com.un.ebs.sys.service.AppRuleService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author liubo
 * @since 2019-09-15
 */
@Service
public class AppRuleServiceImpl extends ServiceImpl<AppRuleMapper, AppRule> implements AppRuleService {

    @Override
    public void add(AppRuleAddDto req) {
        AppRule obj = new AppRule();
        obj.setAppId(req.getAppId());
        obj.setMethods(req.getMethods());
        obj.setUrlPattern(req.getUrlPattern());
        obj.setIsDelete(false);
        obj.setSort(0);
        obj.insert();
    }

    @Override
    public void update(AppRuleUpdateDto req) {
        AppRule obj = getById(req.getId());
        obj.setAppId(req.getAppId());
        obj.setMethods(req.getMethods());
        obj.setUrlPattern(req.getUrlPattern());
        obj.setSort(0);
        obj.updateById();
    }

    @Override
    public AppRule queryById(String id) {
        return getBaseMapper().selectById(id);
    }

    public void delete(String id) {
        getBaseMapper().deleteById(id);
    }

    public void changeSort(String id, int index) {
        AppRule obj = getById(id);
        obj.setSort(index);
        getBaseMapper().updateById(obj);
    }

}